package gitee.cheungming.modules.governance.controller;


import cn.dev33.satoken.oauth2.annotation.SaCheckClientToken;
import cn.dev33.satoken.util.SaResult;
import gitee.cheungming.modules.governance.service.ConditionService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.Timestamp;

//@SaCheckClientToken
@Controller
@RequestMapping("/api/condition")
public class ConditionController {

    @Resource
    ConditionService conditionService;


    @ResponseBody
    @RequestMapping("/ingestion/{count}")
    public SaResult ingestion(@PathVariable Long count,
                              @RequestParam(required = false) String databaseType) {
        conditionService.ingestion(conditionService.createConditionData(count), databaseType);
        return SaResult.ok();
    }

    @ResponseBody
    @RequestMapping("/queryLatest/{vin}")
    public SaResult queryLatest(@PathVariable String vin,
                                @RequestParam(required = false) String databaseType) {
        return SaResult.data(conditionService.queryLatest(vin, databaseType));
    }


    @ResponseBody
    @RequestMapping("/queryHistory")
    public SaResult queryHistory(@RequestParam String vin,
                                 @RequestParam Timestamp start,
                                 @RequestParam Timestamp end,
                                 @RequestParam(required = false) String databaseType) {
        return SaResult.data(conditionService.queryHistory(vin, start, end, databaseType));
    }

}
